<!DOCTYPE html>
<html><head>
	<meta charset="UTF-8">
	<meta http-equiv="x-UA-Compatible" content="ie=Edge">
   	<meta name="viewport" content="width=device-width, initial-scale=1">
   	<title>Crafty - Crafty.math</title>
	<link type="text/css" rel="stylesheet" href="../craftyjs-site.css">
	<link rel="shortcut icon" href="../favicon.ico">
</head>
<body>
	<div id="header-background"> </div>
	<div id="page-frame">
	<div id="header">
		<nav class="navbar">
  			<div class="container-fluid">
  				<div class="navbar-header">
  					<a class="navbar-brand" href="../"> <img class="logo" src="../images/text-logo.png"> </a>
  					
				</div>
				<div class="collapse navbar-collapse navbar-right" id="bs-example-navbar-collapse-1">
					<ul class="nav navbar-nav">
						<li><a href="../">首页</a></li>
						<li><a href="../getting-started/">快速开始</a></li>
						<li><a href="../documentation/">文档</a></li>
						<li><a href="../api/">API</a></li>
						<li><a href="../components/">组件</a></li>
						<li class="emph"><a href="../#install">下载</a></li>
					</ul>
				</div>
			</div>
		</nav>
	</div>


	<div id="main">
		<div id="content" class="container">
			



<div id="docs"><div class="toc-holder" id="doc-nav"><ul id="doc-level-one"><li><a href="events.html">事件列表</a></li><li class="category">核心<ul class="category-list"><li><a href="Crafty.html">Crafty</a></li><li><a href="Crafty Core.html">Crafty Core</a></li><li><a href="Crafty-bind.html">Crafty.bind()</a></li><li><a href="Crafty-c.html">Crafty.c()</a></li><li><a href="Crafty-clone.html">Crafty.clone()</a></li><li><a href="Crafty-defineField.html">Crafty.defineField()</a></li><li><a href="Crafty-e.html">Crafty.e()</a></li><li><a href="Crafty-extend.html">Crafty.extend()</a></li><li><a href="Crafty-frame.html">Crafty.frame()</a></li><li><a href="Crafty-getVersion.html">Crafty.getVersion()</a></li><li><a href="Crafty-init.html">Crafty.init()</a></li><li><a href="Crafty-isPaused.html">Crafty.isPaused()</a></li><li><a href="Crafty-one.html">Crafty.one()</a></li><li><a href="Crafty-pause.html">Crafty.pause()</a></li><li><a href="Crafty-s.html">Crafty.s()</a></li><li><a href="Crafty-settings.html">Crafty.settings</a></li><li><a href="Crafty-stage.html">Crafty.stage</a></li><li><a href="Crafty-stop.html">Crafty.stop()</a></li><li><a href="Crafty-support.html">Crafty.support</a></li><li><a href="Crafty-trigger.html">Crafty.trigger()</a></li><li><a href="Crafty-unbind.html">Crafty.unbind()</a></li><li><a href="Crafty-uniqueBind.html">Crafty.uniqueBind()</a></li></ul></li><li class="category">2D<ul class="category-list"><li><a href="2D.html">2D</a></li><li><a href="AngularMotion.html">AngularMotion</a></li><li><a href="Collision.html">Collision</a></li><li><a href="Crafty-circle.html">Crafty.circle</a></li><li><a href="Crafty-diamondIso.html">Crafty.diamondIso</a></li><li><a href="Crafty-HashMap.html">Crafty.HashMap</a></li><li><a href="Crafty-isometric.html">Crafty.isometric</a></li><li><a href="Crafty-map.html">Crafty.map</a></li><li><a href="Crafty-math-Matrix2D.html">Crafty.math.Matrix2D</a></li><li><a href="Crafty-math-Vector2D.html">Crafty.math.Vector2D</a></li><li><a href="Crafty-polygon.html">Crafty.polygon</a></li><li><a href="Crafty-raycast.html">Crafty.raycast()</a></li><li><a href="Crafty-rectManager.html">Crafty.rectManager</a></li><li><a href="Gravity.html">Gravity</a></li><li><a href="GroundAttacher.html">GroundAttacher</a></li><li><a href="Motion.html">Motion</a></li><li><a href="Supportable.html">Supportable</a></li></ul></li><li class="category">动画<ul class="category-list"><li><a href="Crafty-easing.html">Crafty.easing</a></li><li><a href="SpriteAnimation.html">SpriteAnimation</a></li><li><a href="Tween.html">Tween</a></li></ul></li><li class="category">资源<ul class="category-list"><li><a href="Crafty-asset.html">Crafty.asset()</a></li><li><a href="Crafty-assets.html">Crafty.assets</a></li><li><a href="Crafty-imageWhitelist.html">Crafty.imageWhitelist()</a></li><li><a href="Crafty-load.html">Crafty.load()</a></li><li><a href="Crafty-paths.html">Crafty.paths()</a></li><li><a href="Crafty-removeAssets.html">Crafty.removeAssets()</a></li></ul></li><li class="category">音频<ul class="category-list"><li><a href="Crafty-audio.html">Crafty.audio</a></li></ul></li><li class="category">控制器<ul class="category-list"><li><a href="Controllable.html">Controllable</a></li><li><a href="Controls.html">Controls</a></li><li><a href="Draggable.html">Draggable</a></li><li><a href="Fourway.html">Fourway</a></li><li><a href="Jumper.html">Jumper</a></li><li><a href="Multiway.html">Multiway</a></li><li><a href="Twoway.html">Twoway</a></li></ul></li><li class="category">调试<ul class="category-list"><li><a href="Crafty-error.html">Crafty.error()</a></li><li><a href="Crafty-log.html">Crafty.log()</a></li><li><a href="DebugCanvas.html">DebugCanvas</a></li><li><a href="DebugPolygon.html">DebugPolygon</a></li><li><a href="DebugRectangle.html">DebugRectangle</a></li><li><a href="SolidAreaMap.html">SolidAreaMap</a></li><li><a href="SolidHitBox.html">SolidHitBox</a></li><li><a href="VisibleMBR.html">VisibleMBR</a></li><li><a href="WiredAreaMap.html">WiredAreaMap</a></li><li><a href="WiredHitBox.html">WiredHitBox</a></li></ul></li><li class="category">事件<ul class="category-list"><li><a href="Crafty-addEvent.html">Crafty.addEvent()</a></li><li><a href="Crafty-bind.html">Crafty.bind()</a></li><li><a href="Crafty-one.html">Crafty.one()</a></li><li><a href="Crafty-removeEvent.html">Crafty.removeEvent()</a></li><li><a href="Crafty-trigger.html">Crafty.trigger()</a></li><li><a href="Crafty-unbind.html">Crafty.unbind()</a></li><li><a href="Crafty-uniqueBind.html">Crafty.uniqueBind()</a></li></ul></li><li class="category">游戏循环<ul class="category-list"><li><a href="Crafty-timer.html">Crafty.timer</a></li></ul></li><li class="category">图形<ul class="category-list"><li><a href="Canvas.html">Canvas</a></li><li><a href="CanvasLayer.html">CanvasLayer</a></li><li><a href="Color.html">Color</a></li><li><a href="Crafty-assignColor.html">Crafty.assignColor()</a></li><li><a href="Crafty-background.html">Crafty.background()</a></li><li><a href="Crafty-createLayer.html">Crafty.createLayer()</a></li><li><a href="Crafty-defaultShader.html">Crafty.defaultShader()</a></li><li><a href="Crafty-domHelper.html">Crafty.domHelper</a></li><li><a href="Crafty-pixelart.html">Crafty.pixelart()</a></li><li><a href="Crafty-sprite.html">Crafty.sprite()</a></li><li><a href="Crafty-WebGLShader.html">Crafty.WebGLShader()</a></li><li><a href="DOM.html">DOM</a></li><li><a href="DomLayer.html">DomLayer</a></li><li><a href="HTML.html">HTML</a></li><li><a href="Image.html">Image</a></li><li><a href="Particles.html">Particles</a></li><li><a href="Renderable.html">Renderable</a></li><li><a href="Sprite.html">Sprite</a></li><li><a href="Text.html">Text</a></li><li><a href="WebGL.html">WebGL</a></li><li><a href="WebGLLayer.html">WebGLLayer</a></li></ul></li><li class="category">输入<ul class="category-list"><li><a href="AreaMap.html">AreaMap</a></li><li><a href="Button.html">Button</a></li><li><a href="Crafty-findPointerEventTargetByComponent.html">Crafty.findPointerEventTargetByComponent()</a></li><li><a href="Crafty-keyboardDispatch.html">Crafty.keyboardDispatch()</a></li><li><a href="Crafty-keydown.html">Crafty.keydown</a></li><li><a href="Crafty-keys.html">Crafty.keys</a></li><li><a href="Crafty-lastEvent.html">Crafty.lastEvent</a></li><li><a href="Crafty-mouseButtons.html">Crafty.mouseButtons</a></li><li><a href="Crafty-mouseDispatch.html">Crafty.mouseDispatch()</a></li><li><a href="Crafty-mouseWheelDispatch.html">Crafty.mouseWheelDispatch()</a></li><li><a href="Crafty-multitouch.html">Crafty.multitouch()</a></li><li><a href="Crafty-selected.html">Crafty.selected</a></li><li><a href="Crafty-touchDispatch.html">Crafty.touchDispatch()</a></li><li><a href="Keyboard.html">Keyboard</a></li><li><a href="Mouse.html">Mouse</a></li><li><a href="MouseDrag.html">MouseDrag</a></li><li><a href="Touch.html">Touch</a></li></ul></li><li class="category">杂项<ul class="category-list"><li><a href="Crafty-addEvent.html">Crafty.addEvent()</a></li><li><a href="Crafty-device.html">Crafty.device</a></li><li><a href="Crafty-removeEvent.html">Crafty.removeEvent()</a></li><li><a href="Crafty-support.html">Crafty.support</a></li></ul></li><li class="category">模型<ul class="category-list"><li><a href="Model.html">Model</a></li></ul></li><li class="category">场景<ul class="category-list"><li><a href="Crafty-scene.html">Crafty.scene()</a></li></ul></li><li class="category">舞台<ul class="category-list"><li><a href="Crafty-background.html">Crafty.background()</a></li><li><a href="Crafty-scene.html">Crafty.scene()</a></li><li><a href="Crafty-viewport.html">Crafty.viewport</a></li></ul></li><li class="category">工具<ul class="category-list"><li><a href="Crafty-math.html">Crafty.math</a></li><li><a href="Delay.html">Delay</a></li><li><a href="Storage.html">Storage</a></li></ul></li></ul></div><div id="doc-content" class="doc-page-holder"><div class="doc-page"><h1>Crafty.math <span></span></h1><div class="doclet" id="Crafty-math"><span class="markdown"><p>一组通用（但不常用）的工具函数集合。</p>
</span></div><div><h4>方法</h4><ul class="page-toc"><li><a href="#Crafty-math-abs">.abs()</a></li><li><a href="#Crafty-math-amountOf">.amountOf()</a></li><li><a href="#Crafty-math-clamp">.clamp()</a></li><li><a href="#Crafty-math-degToRad">.degToRad()</a></li><li><a href="#Crafty-math-distance">.distance()</a></li><li><a href="#Crafty-math-lerp">.lerp()</a></li><li><a href="#Crafty-math-negate">.negate()</a></li><li><a href="#Crafty-math-radToDeg">.radToDeg()</a></li><li><a href="#Crafty-math-randomElementOfArray">.randomElementOfArray()</a></li><li><a href="#Crafty-math-randomInt">.randomInt()</a></li><li><a href="#Crafty-math-randomNumber">.randomNumber()</a></li><li><a href="#Crafty-math-squaredDistance">.squaredDistance()</a></li><li><a href="#Crafty-math-withinRange">.withinRange()</a></li></ul><div class="doclet" id="Crafty-math-abs"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">Crafty.math.abs()</h2><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">this </span><span class="sig-noun">Crafty.math.abs</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">Number </span><span class="sig-noun">n</span></span><span class="sig-seperator">)</span></code><dl class="parameter"><dt> n </dt><dd><span class="markdown"><p>数字</p>
</span></dd></dl><dl class="parameter returns"><dt class="returns"> [返回] </dt><dd><span class="markdown"><p>绝对值</p>
</span></dd></dl></div><span class="markdown"><p>返回指定数字的绝对值。</p>
</span></div><div class="doclet" id="Crafty-math-amountOf"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">Crafty.math.amountOf()</h2><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Number </span><span class="sig-noun">Crafty.math.amountOf</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">Number </span><span class="sig-noun">checkValue</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">minValue</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">maxValue</span></span><span class="sig-seperator">)</span></code><dl class="parameter"><dt> checkValue </dt><dd><span class="markdown"><p>介于最小值与最大值之间的数字。</p>
</span></dd></dl><dl class="parameter"><dt> minValue </dt><dd><span class="markdown"><p>最小值</p>
</span></dd></dl><dl class="parameter"><dt> maxValue </dt><dd><span class="markdown"><p>最大值</p>
</span></dd></dl><dl class="parameter returns"><dt class="returns"> [返回] </dt><dd><span class="markdown"><p>根据指定值在最小值与最大值之间的位置，返回0到1之间的一个数。公式：(checkValue-minValue)/(maxValue-checkValue)</p>
</span></dd></dl></div><span class="markdown"><p>如果指定值在最小值与最大值之间，则返回一个0到1之间的数值。</p>
</span></div><div class="doclet" id="Crafty-math-clamp"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">Crafty.math.clamp()</h2><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Number </span><span class="sig-noun">Crafty.math.clamp</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">Number </span><span class="sig-noun">value</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">min</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">max</span></span><span class="sig-seperator">)</span></code><dl class="parameter"><dt> value </dt><dd><span class="markdown"><p>数字</p>
</span></dd></dl><dl class="parameter"><dt> max </dt><dd><span class="markdown"><p>最大值</p>
</span></dd></dl><dl class="parameter"><dt> min </dt><dd><span class="markdown"><p>最小值</p>
</span></dd></dl><dl class="parameter returns"><dt class="returns"> [返回] </dt><dd><span class="markdown"><p>介于最小值与最大值之间的数值</p>
</span></dd></dl></div><span class="markdown"><p>将值限制在指定的范围内。（如果指定值小于最小值则返回最小值，大于最大值则返回最大值，否则返回给定值。）</p>
</span></div><div class="doclet" id="Crafty-math-degToRad"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">Crafty.math.degToRad()</h2><span class="markdown"><p>角度转弧度</p>
</span><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Number </span><span class="sig-noun">degToRad</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-noun">angleInDeg</span></span><span class="sig-seperator">)</span></code><dl class="parameter"><dt> angleInDeg </dt><dd><span class="markdown"><p>角度值</p>
</span></dd></dl><dl class="parameter returns"><dt class="returns"> [返回] </dt><dd><span class="markdown"><p>弧度值</p>
</span></dd></dl></div></div><div class="doclet" id="Crafty-math-distance"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">Crafty.math.distance()</h2><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Number </span><span class="sig-noun">Crafty.math.distance</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">Number </span><span class="sig-noun">x1</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">y1</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">x2</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">y2</span></span><span class="sig-seperator">)</span></code><dl class="parameter"><dt> x1 </dt><dd><span class="markdown"><p>第一点 x 坐标</p>
</span></dd></dl><dl class="parameter"><dt> y1 </dt><dd><span class="markdown"><p>第一点 y 坐标</p>
</span></dd></dl><dl class="parameter"><dt> x2 </dt><dd><span class="markdown"><p>第二点 x 坐标</p>
</span></dd></dl><dl class="parameter"><dt> y2 </dt><dd><span class="markdown"><p>第二点 y 坐标</p>
</span></dd></dl><dl class="parameter returns"><dt class="returns"> [返回] </dt><dd><span class="markdown"><p>两点间的距离</p>
</span></dd></dl></div><span class="markdown"><p>计算两点间的距离</p>
</span></div><div class="doclet" id="Crafty-math-lerp"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">Crafty.math.lerp()</h2><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Number </span><span class="sig-noun">Crafty.math.lerp</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">Number </span><span class="sig-noun">value1</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">value2</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">amount</span></span><span class="sig-seperator">)</span></code><dl class="parameter"><dt> value1 </dt><dd><span class="markdown"><p>第一个值</p>
</span></dd></dl><dl class="parameter"><dt> value2 </dt><dd><span class="markdown"><p>第二个值</p>
</span></dd></dl><dl class="parameter"><dt> amount </dt><dd><span class="markdown"><p>第二个值与第一个值的比率</p>
</span></dd></dl><dl class="parameter returns"><dt class="returns"> [返回] </dt><dd><span class="markdown"><p>线性插值结果</p>
</span></dd></dl></div><span class="markdown"><p>线性插值。如果 amount 为零则返回第一个值，如果 amount 为1则返回第二个值。（实际是 Crafty.math.amountOf 的逆运算）</p>
</span></div><div class="doclet" id="Crafty-math-negate"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">Crafty.math.negate()</h2><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Number </span><span class="sig-noun">Crafty.math.negate</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">Number </span><span class="sig-noun">percent</span></span><span class="sig-seperator">)</span></code><dl class="parameter"><dt> percent </dt><dd><span class="markdown"><p>返回 <code>-1</code> 的概率</p>
</span></dd></dl><dl class="parameter returns"><dt class="returns"> [返回] </dt><dd><span class="markdown"><p>1 或 -1</p>
</span></dd></dl></div><span class="markdown"><p>随机返回 <code>1</code> 或 <code>-1</code> 。</p>
</span></div><div class="doclet" id="Crafty-math-radToDeg"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">Crafty.math.radToDeg()</h2><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Number </span><span class="sig-noun">Crafty.math.radToDeg</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">Number </span><span class="sig-noun">angle</span></span><span class="sig-seperator">)</span></code><dl class="parameter"><dt> angleInRad </dt><dd><span class="markdown"><p>弧度值</p>
</span></dd></dl><dl class="parameter returns"><dt class="returns"> [返回] </dt><dd><span class="markdown"><p>角度值</p>
</span></dd></dl></div><span class="markdown"><p>弧度转角度</p>
</span></div><div class="doclet" id="Crafty-math-randomElementOfArray"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">Crafty.math.randomElementOfArray()</h2><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Object </span><span class="sig-noun">Crafty.math.randomElementOfArray</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">Array </span><span class="sig-noun">array</span></span><span class="sig-seperator">)</span></code><dl class="parameter"><dt> array </dt><dd><span class="markdown"><p>指定数组</p>
</span></dd></dl><dl class="parameter returns"><dt class="returns"> [返回] </dt><dd><span class="markdown"><p>随机返回数组中的一个元素</p>
</span></dd></dl></div><span class="markdown"><p>从指定的数组中随机选择一个元素。</p>
</span></div><div class="doclet" id="Crafty-math-randomInt"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">Crafty.math.randomInt()</h2><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Number </span><span class="sig-noun">Crafty.math.randomInt</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">Number </span><span class="sig-noun">start</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">end</span></span><span class="sig-seperator">)</span></code><dl class="parameter"><dt> start </dt><dd><span class="markdown"><p>最小值</p>
</span></dd></dl><dl class="parameter"><dt> end </dt><dd><span class="markdown"><p>最大值</p>
</span></dd></dl><dl class="parameter returns"><dt class="returns"> [返回] </dt><dd><span class="markdown"><p>一个介于最小值和最大值之间的随机整数</p>
</span></dd></dl></div><span class="markdown"><p>返回一个介于指定范围内的整数。</p>
</span></div><div class="doclet" id="Crafty-math-randomNumber"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">Crafty.math.randomNumber()</h2><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Number </span><span class="sig-noun">Crafty.math.randomNumber</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">Number </span><span class="sig-noun">start</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">end</span></span><span class="sig-seperator">)</span></code><dl class="parameter"><dt> start </dt><dd><span class="markdown"><p>最小值</p>
</span></dd></dl><dl class="parameter"><dt> end </dt><dd><span class="markdown"><p>最大值</p>
</span></dd></dl><dl class="parameter returns"><dt class="returns"> [返回] </dt><dd><span class="markdown"><p>一个介于最小值和最大值之间的数值。</p>
</span></dd></dl></div><span class="markdown"><p>返回一个介于指定范围内的数值。</p>
</span></div><div class="doclet" id="Crafty-math-squaredDistance"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">Crafty.math.squaredDistance()</h2><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Number </span><span class="sig-noun">Crafty.math.squaredDistance</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">Number </span><span class="sig-noun">x1</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">y1</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">x2</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">y2</span></span><span class="sig-seperator">)</span></code><dl class="parameter"><dt> x1 </dt><dd><span class="markdown"><p>第一个点的 x 坐标</p>
</span></dd></dl><dl class="parameter"><dt> y1 </dt><dd><span class="markdown"><p>第一个点的 y 坐标</p>
</span></dd></dl><dl class="parameter"><dt> x2 </dt><dd><span class="markdown"><p>第二个点的 x 坐标</p>
</span></dd></dl><dl class="parameter"><dt> y2 </dt><dd><span class="markdown"><p>第二个点的 y 坐标</p>
</span></dd></dl><dl class="parameter returns"><dt class="returns"> [返回] </dt><dd><span class="markdown"><p>两点间距离的平方</p>
</span></dd></dl></div><span class="markdown"><p>计算两点间距离的平方</p>
</span></div><div class="doclet" id="Crafty-math-withinRange"><a href="#doc-nav" class="doc-top">Back to top</a><h2 class="doclet-header">Crafty.math.withinRange()</h2><div class="crafty-method"><code class="signature"><span class="sig-phrase"><span class="sig-qualifier">public </span><span class="sig-qualifier">Boolean </span><span class="sig-noun">Crafty.math.withinRange</span></span><span class="sig-seperator">(</span><span class="sig-phrase"><span class="sig-qualifier">Number </span><span class="sig-noun">value</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">min</span></span><span class="sig-seperator">,</span><span class="sig-phrase"><span class="sig-qualifier"> </span><span class="sig-qualifier">Number </span><span class="sig-noun">max</span></span><span class="sig-seperator">)</span></code><dl class="parameter"><dt> value </dt><dd><span class="markdown"><p>指定值</p>
</span></dd></dl><dl class="parameter"><dt> min </dt><dd><span class="markdown"><p>最小值</p>
</span></dd></dl><dl class="parameter"><dt> max </dt><dd><span class="markdown"><p>最大值</p>
</span></dd></dl><dl class="parameter returns"><dt class="returns"> [返回] </dt><dd><span class="markdown"><p>如果指定值介于最小值与最大值之间则返回 true</p>
</span></dd></dl></div><span class="markdown"><p>检查一个值是否在指定的范围内。</p>
</span></div></div></div></div></div>
			
		</div>
	</div>
	<div class="clearer"></div>
	<div id="footer">
		<div id="contact">
			<a href="https://groups.google.com/forum/#!forum/craftyjs">
				<img src="../images/google.png">
				google groups</a>
			<a href="mailto:starwed@gmail.com">
				<img src="../images/email.png">
				starwed@gmail.com</a>
			<a href="https://github.com/craftyjs/Crafty">
				<img src="../images/github.png">
				github</a>
		</div>
		<ul>
			<li><a href="../">首页</a></li>
				<li><a href="../getting-started/">快速开始</a></li>
				<li><a href="../documentation/">文档</a></li>
				<li><a href="../api/">API</a></li>
				<li><a href="../components/">组件</a></li>
				<li class="emph"><a href="../#install">下载</a></li>
		</ul>
		<p>
			© Crafty 2010-2015. Crafty is distributed under the <a href="http://en.wikipedia.org/wiki/MIT_License">MIT License</a>.
		</p>
	</div>
</div>



</body></html>